package com.sjgtw.cloud.web.floodPlan.service.impl;

import com.sjgtw.cloud.common.core.constant.CacheConstants;
import com.sjgtw.cloud.common.core.utils.DateUtils;
import com.sjgtw.cloud.common.core.utils.SecurityUtils;
import com.sjgtw.cloud.common.redis.service.RedisService;
import com.sjgtw.cloud.system.api.model.LoginUser;
import com.sjgtw.cloud.web.floodPlan.domain.FloodPlan;
import com.sjgtw.cloud.web.floodPlan.mapper.FloodPlanMapper;
import com.sjgtw.cloud.web.floodPlan.service.IFloodPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 冻害处置方案Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-16
 */
@Service
public class FloodPlanServiceImpl implements IFloodPlanService
{
    @Autowired
    private FloodPlanMapper floodPlanMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 查询冻害处置方案
     * 
     * @param id 冻害处置方案主键
     * @return 冻害处置方案
     */
    @Override
    public FloodPlan selectFloodPlanById(Long id)
    {
        return floodPlanMapper.selectFloodPlanById(id);
    }

    /**
     * 查询冻害处置方案列表
     * 
     * @param floodPlan 冻害处置方案
     * @return 冻害处置方案
     */
    @Override
    public List<Map<String,Object>> selectFloodPlanList(FloodPlan floodPlan)
    {
        return floodPlanMapper.selectFloodPlanList(floodPlan);
    }

    /**
     * 新增冻害处置方案
     * 
     * @param floodPlan 冻害处置方案
     * @return 结果
     */
    @Override
    public int insertFloodPlan(FloodPlan floodPlan)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        floodPlan.setCreateBy(user.getUsername());
        floodPlan.setCreateTime(DateUtils.getNowDate());
        return floodPlanMapper.insertFloodPlan(floodPlan);
    }

    /**
     * 修改冻害处置方案
     * 
     * @param floodPlan 冻害处置方案
     * @return 结果
     */
    @Override
    public int updateFloodPlan(FloodPlan floodPlan)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        floodPlan.setUpdateBy(user.getUsername());
        floodPlan.setUpdateTime(DateUtils.getNowDate());
        return floodPlanMapper.updateFloodPlan(floodPlan);
    }

    /**
     * 批量删除冻害处置方案
     * 
     * @param ids 需要删除的冻害处置方案主键
     * @return 结果
     */
    @Override
    public int deleteFloodPlanByIds(Long[] ids)
    {
        return floodPlanMapper.deleteFloodPlanByIds(ids);
    }

    /**
     * 删除冻害处置方案信息
     * 
     * @param id 冻害处置方案主键
     * @return 结果
     */
    @Override
    public int deleteFloodPlanById(Long id)
    {
        return floodPlanMapper.deleteFloodPlanById(id);
    }
}
